package com.example.common.lang;

import lombok.Data;
import java.io.Serializable;

/**
 * 统一结果数据封装类
 */

@Data
public class Result implements Serializable {

    private int code;           //验证码
    private String msg;         //图片
    private Object data;        //数据对象


    //成功时返回的数据
    public static Result succ (Object data) {

        return succ(200,"操作成功",data);
    }

    //成功时返回
    public static Result succ (int code,String msg,Object data) {
        Result r = new Result();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

    //失败时返回的数据
    public static Result fail (String msg) {

        return fail(400,msg,null);
    }

    //失败时返回
    public static Result fail (int code,String msg,Object data) {
        Result r = new Result();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

}
